use std::sync::Mutex;

use tauri::{AppHandle, Manager};

use crate::model::AppState;

pub fn app_exit(app: &AppHandle) -> Result<(), String> {
    let state = app.state::<Mutex<AppState>>();
    let mut state = state.lock().expect("Failed to acquire lock");
    state.kill_all_service();

    log::info!("quit menu item was clicked");
    app.cleanup_before_exit();
    app.exit(0);

    Ok(())
}
